<template>
    <div>
        <h1>会员权益列表</h1>
        <table class="table table-bordered" >
            <tbody>
                <tr>
                    <td>会员权益名称</td>
                    <td>会员权益状态</td>
                    
                </tr>
                <tr v-for="item in data.list">
                    <td>{{ item.huiYuanQYName }}</td>
                    <td>{{ item.huiYuanQYStare==1?'启用':'禁用' }}</td>
                    <td>
                        <button @click="update(item.id)" >修改</button>
                        <button @click="upstare(item.id)" >修改状态</button>
                        <button @click="del(item.id)" >删除</button>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue';
import axios from 'axios';
import moment from 'moment';
import { useRouter, useRoute } from 'vue-router';

const router = useRouter();
const route = useRoute();

let data: any = reactive({
    list: [], 
})
onMounted(() => {
   HuiYanqyList();
});
const HuiYanqyList=()=>{
    axios({
        url: '/api/HuiYuan/ShowHuiYuanQY',
        method: 'get',
        
    }) 
  .then((res)=>{
    data.list = res.data;
    console.log(data.list);
     
  })
 .catch((err)=>{
      console.log(err);
  }) 
 
}
const del=(id:any)=>{
    axios({
        url: '/api/HuiYuan/del',
        method: 'get',
        params: { id: id }
    }) 
 .then((res)=>{
    if(res.data=1){
        alert('删除成功')
        
        HuiYanqyList();
    }
    else{
        alert('删除失败')
        return;
    }

  })
.catch((err)=>{
      console.log(err);
  }) 

}
const upstare=(id:any)=>{
    axios({
        url: '/api/HuiYuan/Uptype',
        method: 'get',
        params: { id: id }
    }) 
 .then((res)=>{
    if(res.data=1){
        alert('修改状态成功')

        HuiYanqyList();
    }
    else{
        alert('修改状态失败')
        return;
       
    }

  })
.catch((err)=>{
      console.log(err);
  }) 

}
const update=(id:any)=>{
    router.push({ path: '/UpdateHuiYuanQy', query: { id: id } });
}
</script>

<style scoped>

</style>